package h.a.a;

import android.database.CrossProcessCursor;
import android.database.Cursor;
import android.database.CursorWindow;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;
import h.a.a.h.c;
import h.a.a.i.b;
import h.a.a.j.d;
import h.a.a.j.e;
import h.a.a.k.f;
import h.a.a.k.g;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import rx.schedulers.Schedulers;

/* compiled from: AbstractDao */
public abstract class a<T, K> {
    public final h.a.a.j.a config;
    public final h.a.a.h.a db;
    public final h.a.a.i.a<K, T> identityScope;
    public final b<T> identityScopeLong;
    public final boolean isStandardSQLite;
    public final int pkOrdinal;
    private volatile h.a.a.l.b<T, K> rxDao;
    private volatile h.a.a.l.b<T, K> rxDaoPlain;
    public final c session;
    public final e statements;

    public a(h.a.a.j.a aVar) {
        this(aVar, null);
    }

    private void deleteByKeyInsideSynchronized(K k, c cVar) {
        if (k instanceof Long) {
            cVar.c(1, ((Long) k).longValue());
        } else if (k != null) {
            cVar.b(1, k.toString());
        } else {
            throw new d("Cannot delete entity, key is null");
        }
        cVar.execute();
    }

    /* JADX WARNING: Removed duplicated region for block: B:13:0x0029 A:{Catch:{ all -> 0x003a }} */
    /* JADX WARNING: Removed duplicated region for block: B:13:0x0029 A:{Catch:{ all -> 0x003a }} */
    private void deleteInTxInternal(java.lang.Iterable<T> r4, java.lang.Iterable<K> r5) {
        /*
        r3 = this;
        r3.assertSinglePk();
        r0 = r3.statements;
        r0 = r0.a();
        r1 = r3.db;
        r1.c();
        monitor-enter(r0);	 Catch:{ all -> 0x007c }
        r1 = r3.identityScope;	 Catch:{ all -> 0x0079 }
        if (r1 == 0) goto L_0x001c;
    L_0x0013:
        r1.e();	 Catch:{ all -> 0x0079 }
        r1 = new java.util.ArrayList;	 Catch:{ all -> 0x0079 }
        r1.<init>();	 Catch:{ all -> 0x0079 }
        goto L_0x001d;
    L_0x001c:
        r1 = 0;
    L_0x001d:
        if (r4 == 0) goto L_0x003c;
    L_0x001f:
        r4 = r4.iterator();	 Catch:{ all -> 0x003a }
    L_0x0023:
        r2 = r4.hasNext();	 Catch:{ all -> 0x003a }
        if (r2 == 0) goto L_0x003c;
    L_0x0029:
        r2 = r4.next();	 Catch:{ all -> 0x003a }
        r2 = r3.getKeyVerified(r2);	 Catch:{ all -> 0x003a }
        r3.deleteByKeyInsideSynchronized(r2, r0);	 Catch:{ all -> 0x003a }
        if (r1 == 0) goto L_0x0023;
    L_0x0036:
        r1.add(r2);	 Catch:{ all -> 0x003a }
        goto L_0x0023;
    L_0x003a:
        r4 = move-exception;
        goto L_0x0055;
    L_0x003c:
        if (r5 == 0) goto L_0x005d;
    L_0x003e:
        r4 = r5.iterator();	 Catch:{ all -> 0x003a }
    L_0x0042:
        r5 = r4.hasNext();	 Catch:{ all -> 0x003a }
        if (r5 == 0) goto L_0x005d;
    L_0x0048:
        r5 = r4.next();	 Catch:{ all -> 0x003a }
        r3.deleteByKeyInsideSynchronized(r5, r0);	 Catch:{ all -> 0x003a }
        if (r1 == 0) goto L_0x0042;
    L_0x0051:
        r1.add(r5);	 Catch:{ all -> 0x003a }
        goto L_0x0042;
    L_0x0055:
        r5 = r3.identityScope;	 Catch:{ all -> 0x0079 }
        if (r5 == 0) goto L_0x005c;
    L_0x0059:
        r5.c();	 Catch:{ all -> 0x0079 }
    L_0x005c:
        throw r4;	 Catch:{ all -> 0x0079 }
    L_0x005d:
        r4 = r3.identityScope;	 Catch:{ all -> 0x0079 }
        if (r4 == 0) goto L_0x0064;
    L_0x0061:
        r4.c();	 Catch:{ all -> 0x0079 }
    L_0x0064:
        monitor-exit(r0);	 Catch:{ all -> 0x0079 }
        r4 = r3.db;	 Catch:{ all -> 0x007c }
        r4.g();	 Catch:{ all -> 0x007c }
        if (r1 == 0) goto L_0x0073;
    L_0x006c:
        r4 = r3.identityScope;	 Catch:{ all -> 0x007c }
        if (r4 == 0) goto L_0x0073;
    L_0x0070:
        r4.d(r1);	 Catch:{ all -> 0x007c }
    L_0x0073:
        r4 = r3.db;
        r4.b();
        return;
    L_0x0079:
        r4 = move-exception;
        monitor-exit(r0);	 Catch:{ all -> 0x0079 }
        throw r4;	 Catch:{ all -> 0x007c }
    L_0x007c:
        r4 = move-exception;
        r5 = r3.db;
        r5.b();
        throw r4;
        */
        throw new UnsupportedOperationException("Method not decompiled: h.a.a.a.deleteInTxInternal(java.lang.Iterable, java.lang.Iterable):void");
    }

    private long executeInsert(T t, c cVar, boolean z) {
        long insertInsideTx;
        if (this.db.a()) {
            insertInsideTx = insertInsideTx(t, cVar);
        } else {
            insertInsideTx = this.db;
            insertInsideTx.c();
            try {
                insertInsideTx = insertInsideTx(t, cVar);
                this.db.g();
            } finally {
                this.db.b();
            }
        }
        if (z) {
            updateKeyAfterInsertAndAttach(t, insertInsideTx, true);
        }
        return insertInsideTx;
    }

    /* JADX WARNING: Missing block: B:35:0x0076, code skipped:
            r5.db.b();
     */
    private void executeInsertInTx(h.a.a.h.c r6, java.lang.Iterable<T> r7, boolean r8) {
        /*
        r5 = this;
        r0 = r5.db;
        r0.c();
        monitor-enter(r6);	 Catch:{ all -> 0x0075 }
        r0 = r5.identityScope;	 Catch:{ all -> 0x0072 }
        if (r0 == 0) goto L_0x000d;
    L_0x000a:
        r0.e();	 Catch:{ all -> 0x0072 }
    L_0x000d:
        r0 = r5.isStandardSQLite;	 Catch:{ all -> 0x0069 }
        r1 = 0;
        if (r0 == 0) goto L_0x0037;
    L_0x0012:
        r0 = r6.e();	 Catch:{ all -> 0x0069 }
        r0 = (android.database.sqlite.SQLiteStatement) r0;	 Catch:{ all -> 0x0069 }
        r7 = r7.iterator();	 Catch:{ all -> 0x0069 }
    L_0x001c:
        r2 = r7.hasNext();	 Catch:{ all -> 0x0069 }
        if (r2 == 0) goto L_0x0056;
    L_0x0022:
        r2 = r7.next();	 Catch:{ all -> 0x0069 }
        r5.bindValues(r0, r2);	 Catch:{ all -> 0x0069 }
        if (r8 == 0) goto L_0x0033;
    L_0x002b:
        r3 = r0.executeInsert();	 Catch:{ all -> 0x0069 }
        r5.updateKeyAfterInsertAndAttach(r2, r3, r1);	 Catch:{ all -> 0x0069 }
        goto L_0x001c;
    L_0x0033:
        r0.execute();	 Catch:{ all -> 0x0069 }
        goto L_0x001c;
    L_0x0037:
        r7 = r7.iterator();	 Catch:{ all -> 0x0069 }
    L_0x003b:
        r0 = r7.hasNext();	 Catch:{ all -> 0x0069 }
        if (r0 == 0) goto L_0x0056;
    L_0x0041:
        r0 = r7.next();	 Catch:{ all -> 0x0069 }
        r5.bindValues(r6, r0);	 Catch:{ all -> 0x0069 }
        if (r8 == 0) goto L_0x0052;
    L_0x004a:
        r2 = r6.f();	 Catch:{ all -> 0x0069 }
        r5.updateKeyAfterInsertAndAttach(r0, r2, r1);	 Catch:{ all -> 0x0069 }
        goto L_0x003b;
    L_0x0052:
        r6.execute();	 Catch:{ all -> 0x0069 }
        goto L_0x003b;
    L_0x0056:
        r7 = r5.identityScope;	 Catch:{ all -> 0x0072 }
        if (r7 == 0) goto L_0x005d;
    L_0x005a:
        r7.c();	 Catch:{ all -> 0x0072 }
    L_0x005d:
        monitor-exit(r6);	 Catch:{ all -> 0x0072 }
        r6 = r5.db;	 Catch:{ all -> 0x0075 }
        r6.g();	 Catch:{ all -> 0x0075 }
        r6 = r5.db;
        r6.b();
        return;
    L_0x0069:
        r7 = move-exception;
        r8 = r5.identityScope;	 Catch:{ all -> 0x0072 }
        if (r8 == 0) goto L_0x0071;
    L_0x006e:
        r8.c();	 Catch:{ all -> 0x0072 }
    L_0x0071:
        throw r7;	 Catch:{ all -> 0x0072 }
    L_0x0072:
        r7 = move-exception;
        monitor-exit(r6);	 Catch:{ all -> 0x0072 }
        throw r7;	 Catch:{ all -> 0x0075 }
    L_0x0075:
        r6 = move-exception;
        r7 = r5.db;
        r7.b();
        throw r6;
        */
        throw new UnsupportedOperationException("Method not decompiled: h.a.a.a.executeInsertInTx(h.a.a.h.c, java.lang.Iterable, boolean):void");
    }

    private long insertInsideTx(T t, c cVar) {
        synchronized (cVar) {
            long executeInsert;
            if (this.isStandardSQLite) {
                SQLiteStatement sQLiteStatement = (SQLiteStatement) cVar.e();
                bindValues(sQLiteStatement, (Object) t);
                executeInsert = sQLiteStatement.executeInsert();
                return executeInsert;
            }
            bindValues(cVar, (Object) t);
            executeInsert = cVar.f();
            return executeInsert;
        }
    }

    private void loadAllUnlockOnWindowBounds(Cursor cursor, CursorWindow cursorWindow, List<T> list) {
        int numRows = cursorWindow.getNumRows() + cursorWindow.getStartPosition();
        int i = 0;
        while (true) {
            list.add(loadCurrent(cursor, 0, false));
            i++;
            if (i >= numRows) {
                cursorWindow = moveToNextUnlocked(cursor);
                if (cursorWindow != null) {
                    numRows = cursorWindow.getNumRows() + cursorWindow.getStartPosition();
                } else {
                    return;
                }
            } else if (!cursor.moveToNext()) {
                return;
            }
            i++;
        }
    }

    private CursorWindow moveToNextUnlocked(Cursor cursor) {
        this.identityScope.c();
        try {
            CursorWindow window;
            if (cursor.moveToNext()) {
                window = ((CrossProcessCursor) cursor).getWindow();
            } else {
                window = null;
            }
            this.identityScope.e();
            return window;
        } catch (Throwable th) {
            this.identityScope.e();
        }
    }

    public void assertSinglePk() {
        if (this.config.e.length != 1) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(this);
            stringBuilder.append(" (");
            throw new d(c.b.a.a.a.d(stringBuilder, this.config.b, ") does not have a single-column primary key"));
        }
    }

    public void attachEntity(T t) {
    }

    public final void attachEntity(K k, T t, boolean z) {
        attachEntity(t);
        h.a.a.i.a aVar = this.identityScope;
        if (aVar != null && k != null) {
            if (z) {
                aVar.put(k, t);
            } else {
                aVar.a(k, t);
            }
        }
    }

    public abstract void bindValues(SQLiteStatement sQLiteStatement, T t);

    public abstract void bindValues(c cVar, T t);

    public long count() {
        e eVar = this.statements;
        if (eVar.i == null) {
            String str = eVar.b;
            int i = d.a;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("SELECT COUNT(*) FROM \"");
            stringBuilder.append(str);
            stringBuilder.append('\"');
            eVar.i = eVar.a.e(stringBuilder.toString());
        }
        return eVar.i.a();
    }

    public void delete(T t) {
        assertSinglePk();
        deleteByKey(getKeyVerified(t));
    }

    public void deleteAll() {
        h.a.a.h.a aVar = this.db;
        StringBuilder g = c.b.a.a.a.g("DELETE FROM '");
        g.append(this.config.b);
        g.append("'");
        aVar.d(g.toString());
        h.a.a.i.a aVar2 = this.identityScope;
        if (aVar2 != null) {
            aVar2.clear();
        }
    }

    public void deleteByKey(K k) {
        assertSinglePk();
        c a = this.statements.a();
        if (this.db.a()) {
            synchronized (a) {
                deleteByKeyInsideSynchronized(k, a);
            }
        } else {
            this.db.c();
            try {
                synchronized (a) {
                    deleteByKeyInsideSynchronized(k, a);
                }
                this.db.g();
                this.db.b();
            } catch (Throwable th) {
                this.db.b();
            }
        }
        h.a.a.i.a aVar = this.identityScope;
        if (aVar != null) {
            aVar.remove(k);
        }
    }

    public void deleteByKeyInTx(Iterable<K> iterable) {
        deleteInTxInternal(null, iterable);
    }

    public void deleteInTx(Iterable<T> iterable) {
        deleteInTxInternal(iterable, null);
    }

    public boolean detach(T t) {
        if (this.identityScope == null) {
            return false;
        }
        return this.identityScope.b(getKeyVerified(t), t);
    }

    public void detachAll() {
        h.a.a.i.a aVar = this.identityScope;
        if (aVar != null) {
            aVar.clear();
        }
    }

    public String[] getAllColumns() {
        return this.config.d;
    }

    public h.a.a.h.a getDatabase() {
        return this.db;
    }

    public abstract K getKey(T t);

    public K getKeyVerified(T t) {
        Object key = getKey(t);
        if (key != null) {
            return key;
        }
        Objects.requireNonNull(t, "Entity may not be null");
        throw new d("Entity has no key");
    }

    public String[] getNonPkColumns() {
        return this.config.f;
    }

    public String[] getPkColumns() {
        return this.config.e;
    }

    public f getPkProperty() {
        return this.config.g;
    }

    public f[] getProperties() {
        return this.config.c;
    }

    public c getSession() {
        return this.session;
    }

    public e getStatements() {
        return this.config.i;
    }

    public String getTablename() {
        return this.config.b;
    }

    public abstract boolean hasKey(T t);

    public long insert(T t) {
        return executeInsert(t, this.statements.c(), true);
    }

    public void insertInTx(Iterable<T> iterable) {
        insertInTx(iterable, isEntityUpdateable());
    }

    public long insertOrReplace(T t) {
        return executeInsert(t, this.statements.b(), true);
    }

    public void insertOrReplaceInTx(Iterable<T> iterable, boolean z) {
        executeInsertInTx(this.statements.b(), iterable, z);
    }

    public long insertWithoutSettingPk(T t) {
        return executeInsert(t, this.statements.b(), false);
    }

    public abstract boolean isEntityUpdateable();

    public T load(K k) {
        assertSinglePk();
        if (k == null) {
            return null;
        }
        h.a.a.i.a aVar = this.identityScope;
        if (aVar != null) {
            Object obj = aVar.get(k);
            if (obj != null) {
                return obj;
            }
        }
        return loadUniqueAndCloseCursor(this.db.h(this.statements.e(), new String[]{k.toString()}));
    }

    public List<T> loadAll() {
        return loadAllAndCloseCursor(this.db.h(this.statements.d(), null));
    }

    public List<T> loadAllAndCloseCursor(Cursor cursor) {
        try {
            List<T> loadAllFromCursor = loadAllFromCursor(cursor);
            return loadAllFromCursor;
        } finally {
            cursor.close();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:28:0x0079  */
    /* JADX WARNING: Removed duplicated region for block: B:15:0x0050  */
    public java.util.List<T> loadAllFromCursor(android.database.Cursor r7) {
        /*
        r6 = this;
        r0 = r7.getCount();
        if (r0 != 0) goto L_0x000c;
    L_0x0006:
        r7 = new java.util.ArrayList;
        r7.<init>();
        return r7;
    L_0x000c:
        r1 = new java.util.ArrayList;
        r1.<init>(r0);
        r2 = 0;
        r3 = r7 instanceof android.database.CrossProcessCursor;
        r4 = 0;
        if (r3 == 0) goto L_0x0049;
    L_0x0017:
        r2 = r7;
        r2 = (android.database.CrossProcessCursor) r2;
        r2 = r2.getWindow();
        if (r2 == 0) goto L_0x0049;
    L_0x0020:
        r3 = r2.getNumRows();
        if (r3 != r0) goto L_0x002d;
    L_0x0026:
        r7 = new h.a.a.j.b;
        r7.m4847init(r2);
        r3 = 1;
        goto L_0x004a;
    L_0x002d:
        r3 = "Window vs. result size: ";
        r3 = c.b.a.a.a.g(r3);
        r5 = r2.getNumRows();
        r3.append(r5);
        r5 = "/";
        r3.append(r5);
        r3.append(r0);
        r3 = r3.toString();
        c.j.a.c.y.a.i.y(r3);
    L_0x0049:
        r3 = 0;
    L_0x004a:
        r5 = r7.moveToFirst();
        if (r5 == 0) goto L_0x0086;
    L_0x0050:
        r5 = r6.identityScope;
        if (r5 == 0) goto L_0x005c;
    L_0x0054:
        r5.e();
        r5 = r6.identityScope;
        r5.g(r0);
    L_0x005c:
        if (r3 != 0) goto L_0x0068;
    L_0x005e:
        if (r2 == 0) goto L_0x0068;
    L_0x0060:
        r0 = r6.identityScope;	 Catch:{ all -> 0x007d }
        if (r0 == 0) goto L_0x0068;
    L_0x0064:
        r6.loadAllUnlockOnWindowBounds(r7, r2, r1);	 Catch:{ all -> 0x007d }
        goto L_0x0075;
    L_0x0068:
        r0 = r6.loadCurrent(r7, r4, r4);	 Catch:{ all -> 0x007d }
        r1.add(r0);	 Catch:{ all -> 0x007d }
        r0 = r7.moveToNext();	 Catch:{ all -> 0x007d }
        if (r0 != 0) goto L_0x0068;
    L_0x0075:
        r7 = r6.identityScope;
        if (r7 == 0) goto L_0x0086;
    L_0x0079:
        r7.c();
        goto L_0x0086;
    L_0x007d:
        r7 = move-exception;
        r0 = r6.identityScope;
        if (r0 == 0) goto L_0x0085;
    L_0x0082:
        r0.c();
    L_0x0085:
        throw r7;
    L_0x0086:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: h.a.a.a.loadAllFromCursor(android.database.Cursor):java.util.List");
    }

    public T loadByRowId(long j) {
        String[] strArr = new String[]{Long.toString(j)};
        h.a.a.h.a aVar = this.db;
        e eVar = this.statements;
        if (eVar.l == null) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(eVar.d());
            stringBuilder.append("WHERE ROWID=?");
            eVar.l = stringBuilder.toString();
        }
        return loadUniqueAndCloseCursor(aVar.h(eVar.l, strArr));
    }

    public final T loadCurrent(Cursor cursor, int i, boolean z) {
        T t = null;
        Object readEntity;
        if (this.identityScopeLong != null) {
            if (i != 0 && cursor.isNull(this.pkOrdinal + i)) {
                return null;
            }
            T h;
            long j = cursor.getLong(this.pkOrdinal + i);
            b bVar = this.identityScopeLong;
            if (z) {
                h = bVar.h(j);
            } else {
                Reference reference = (Reference) bVar.a.a(j);
                if (reference != null) {
                    t = reference.get();
                }
                h = t;
            }
            if (h != null) {
                return h;
            }
            readEntity = readEntity(cursor, i);
            attachEntity(readEntity);
            if (z) {
                this.identityScopeLong.i(j, readEntity);
            } else {
                this.identityScopeLong.a.b(j, new WeakReference(readEntity));
            }
            return readEntity;
        } else if (this.identityScope != null) {
            Object readKey = readKey(cursor, i);
            if (i != 0 && readKey == null) {
                return null;
            }
            h.a.a.i.a aVar = this.identityScope;
            t = z ? aVar.get(readKey) : aVar.f(readKey);
            if (t != null) {
                return t;
            }
            readEntity = readEntity(cursor, i);
            attachEntity(readKey, readEntity, z);
            return readEntity;
        } else if (i != 0 && readKey(cursor, i) == null) {
            return null;
        } else {
            readEntity = readEntity(cursor, i);
            attachEntity(readEntity);
            return readEntity;
        }
    }

    public final <O> O loadCurrentOther(a<O, ?> aVar, Cursor cursor, int i) {
        return aVar.loadCurrent(cursor, i, true);
    }

    public T loadUnique(Cursor cursor) {
        if (!cursor.moveToFirst()) {
            return null;
        }
        if (cursor.isLast()) {
            return loadCurrent(cursor, 0, true);
        }
        StringBuilder g = c.b.a.a.a.g("Expected unique result, but count was ");
        g.append(cursor.getCount());
        throw new d(g.toString());
    }

    public T loadUniqueAndCloseCursor(Cursor cursor) {
        try {
            T loadUnique = loadUnique(cursor);
            return loadUnique;
        } finally {
            cursor.close();
        }
    }

    public g<T> queryBuilder() {
        return new g(this);
    }

    public List<T> queryRaw(String str, String... strArr) {
        h.a.a.h.a aVar = this.db;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(this.statements.d());
        stringBuilder.append(str);
        return loadAllAndCloseCursor(aVar.h(stringBuilder.toString(), strArr));
    }

    public f<T> queryRawCreate(String str, Object... objArr) {
        return queryRawCreateListArgs(str, Arrays.asList(objArr));
    }

    public f<T> queryRawCreateListArgs(String str, Collection<Object> collection) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(this.statements.d());
        stringBuilder.append(str);
        return f.c(this, stringBuilder.toString(), collection.toArray(), -1, -1);
    }

    public abstract T readEntity(Cursor cursor, int i);

    public abstract void readEntity(Cursor cursor, T t, int i);

    public abstract K readKey(Cursor cursor, int i);

    public void refresh(T t) {
        assertSinglePk();
        Object keyVerified = getKeyVerified(t);
        Cursor h = this.db.h(this.statements.e(), new String[]{keyVerified.toString()});
        try {
            if (!h.moveToFirst()) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Entity does not exist in the database anymore: ");
                stringBuilder.append(t.getClass());
                stringBuilder.append(" with key ");
                stringBuilder.append(keyVerified);
                throw new d(stringBuilder.toString());
            } else if (h.isLast()) {
                readEntity(h, t, 0);
                attachEntity(keyVerified, t, true);
            } else {
                StringBuilder stringBuilder2 = new StringBuilder();
                stringBuilder2.append("Expected unique result, but count was ");
                stringBuilder2.append(h.getCount());
                throw new d(stringBuilder2.toString());
            }
        } finally {
            h.close();
        }
    }

    public h.a.a.l.b<T, K> rx() {
        if (this.rxDao == null) {
            this.rxDao = new h.a.a.l.b(this, Schedulers.io());
        }
        return this.rxDao;
    }

    public h.a.a.l.b<T, K> rxPlain() {
        if (this.rxDaoPlain == null) {
            this.rxDaoPlain = new h.a.a.l.b(this);
        }
        return this.rxDaoPlain;
    }

    public void save(T t) {
        if (hasKey(t)) {
            update(t);
        } else {
            insert(t);
        }
    }

    public void saveInTx(T... tArr) {
        saveInTx(Arrays.asList(tArr));
    }

    public void update(T t) {
        assertSinglePk();
        c f = this.statements.f();
        if (this.db.a()) {
            synchronized (f) {
                if (this.isStandardSQLite) {
                    updateInsideSynchronized((Object) t, (SQLiteStatement) f.e(), true);
                } else {
                    updateInsideSynchronized((Object) t, f, true);
                }
            }
            return;
        }
        this.db.c();
        try {
            synchronized (f) {
                updateInsideSynchronized((Object) t, f, true);
            }
            this.db.g();
            this.db.b();
        } catch (Throwable th) {
            this.db.b();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:40:0x0076  */
    /* JADX WARNING: Removed duplicated region for block: B:39:0x0075 A:{RETURN} */
    public void updateInTx(java.lang.Iterable<T> r5) {
        /*
        r4 = this;
        r0 = r4.statements;
        r0 = r0.f();
        r1 = r4.db;
        r1.c();
        monitor-enter(r0);	 Catch:{ RuntimeException -> 0x006d, all -> 0x0064 }
        r1 = r4.identityScope;	 Catch:{ all -> 0x0061 }
        if (r1 == 0) goto L_0x0013;
    L_0x0010:
        r1.e();	 Catch:{ all -> 0x0061 }
    L_0x0013:
        r1 = r4.isStandardSQLite;	 Catch:{ all -> 0x0058 }
        r2 = 0;
        if (r1 == 0) goto L_0x0030;
    L_0x0018:
        r1 = r0.e();	 Catch:{ all -> 0x0058 }
        r1 = (android.database.sqlite.SQLiteStatement) r1;	 Catch:{ all -> 0x0058 }
        r5 = r5.iterator();	 Catch:{ all -> 0x0058 }
    L_0x0022:
        r3 = r5.hasNext();	 Catch:{ all -> 0x0058 }
        if (r3 == 0) goto L_0x0042;
    L_0x0028:
        r3 = r5.next();	 Catch:{ all -> 0x0058 }
        r4.updateInsideSynchronized(r3, r1, r2);	 Catch:{ all -> 0x0058 }
        goto L_0x0022;
    L_0x0030:
        r5 = r5.iterator();	 Catch:{ all -> 0x0058 }
    L_0x0034:
        r1 = r5.hasNext();	 Catch:{ all -> 0x0058 }
        if (r1 == 0) goto L_0x0042;
    L_0x003a:
        r1 = r5.next();	 Catch:{ all -> 0x0058 }
        r4.updateInsideSynchronized(r1, r0, r2);	 Catch:{ all -> 0x0058 }
        goto L_0x0034;
    L_0x0042:
        r5 = r4.identityScope;	 Catch:{ all -> 0x0061 }
        if (r5 == 0) goto L_0x0049;
    L_0x0046:
        r5.c();	 Catch:{ all -> 0x0061 }
    L_0x0049:
        monitor-exit(r0);	 Catch:{ all -> 0x0061 }
        r5 = r4.db;	 Catch:{ RuntimeException -> 0x006d, all -> 0x0064 }
        r5.g();	 Catch:{ RuntimeException -> 0x006d, all -> 0x0064 }
        r5 = r4.db;	 Catch:{ RuntimeException -> 0x0056 }
        r5.b();	 Catch:{ RuntimeException -> 0x0056 }
        r5 = 0;
        goto L_0x0073;
    L_0x0056:
        r5 = move-exception;
        throw r5;
    L_0x0058:
        r5 = move-exception;
        r1 = r4.identityScope;	 Catch:{ all -> 0x0061 }
        if (r1 == 0) goto L_0x0060;
    L_0x005d:
        r1.c();	 Catch:{ all -> 0x0061 }
    L_0x0060:
        throw r5;	 Catch:{ all -> 0x0061 }
    L_0x0061:
        r5 = move-exception;
        monitor-exit(r0);	 Catch:{ all -> 0x0061 }
        throw r5;	 Catch:{ RuntimeException -> 0x006d, all -> 0x0064 }
    L_0x0064:
        r5 = move-exception;
        r0 = r4.db;	 Catch:{ RuntimeException -> 0x006b }
        r0.b();	 Catch:{ RuntimeException -> 0x006b }
        throw r5;
    L_0x006b:
        r5 = move-exception;
        throw r5;
    L_0x006d:
        r5 = move-exception;
        r0 = r4.db;	 Catch:{ RuntimeException -> 0x0077 }
        r0.b();	 Catch:{ RuntimeException -> 0x0077 }
    L_0x0073:
        if (r5 != 0) goto L_0x0076;
    L_0x0075:
        return;
    L_0x0076:
        throw r5;
    L_0x0077:
        r0 = move-exception;
        r1 = "Could not end transaction (rethrowing initial exception)";
        c.j.a.c.y.a.i.H(r1, r0);
        throw r5;
        */
        throw new UnsupportedOperationException("Method not decompiled: h.a.a.a.updateInTx(java.lang.Iterable):void");
    }

    public void updateInsideSynchronized(T t, c cVar, boolean z) {
        bindValues(cVar, (Object) t);
        int length = this.config.d.length + 1;
        Object key = getKey(t);
        if (key instanceof Long) {
            cVar.c(length, ((Long) key).longValue());
        } else if (key != null) {
            cVar.b(length, key.toString());
        } else {
            throw new d("Cannot update entity without key - was it inserted before?");
        }
        cVar.execute();
        attachEntity(key, t, z);
    }

    public abstract K updateKeyAfterInsert(T t, long j);

    public void updateKeyAfterInsertAndAttach(T t, long j, boolean z) {
        if (j != -1) {
            attachEntity(updateKeyAfterInsert(t, j), t, z);
        } else {
            Log.w("greenDAO", "Could not insert row (executeInsert returned -1)");
        }
    }

    public a(h.a.a.j.a aVar, c cVar) {
        this.config = aVar;
        this.session = cVar;
        h.a.a.h.a aVar2 = aVar.a;
        this.db = aVar2;
        this.isStandardSQLite = aVar2.f() instanceof SQLiteDatabase;
        h.a.a.i.a aVar3 = aVar.j;
        this.identityScope = aVar3;
        if (aVar3 instanceof b) {
            this.identityScopeLong = (b) aVar3;
        } else {
            this.identityScopeLong = null;
        }
        this.statements = aVar.i;
        f fVar = aVar.g;
        this.pkOrdinal = fVar != null ? fVar.a : -1;
    }

    public void deleteByKeyInTx(K... kArr) {
        deleteInTxInternal(null, Arrays.asList(kArr));
    }

    public void deleteInTx(T... tArr) {
        deleteInTxInternal(Arrays.asList(tArr), null);
    }

    public void insertInTx(T... tArr) {
        insertInTx(Arrays.asList(tArr), isEntityUpdateable());
    }

    public void saveInTx(Iterable<T> iterable) {
        int i = 0;
        int i2 = 0;
        for (T hasKey : iterable) {
            if (hasKey(hasKey)) {
                i++;
            } else {
                i2++;
            }
        }
        if (i > 0 && i2 > 0) {
            Iterable arrayList = new ArrayList(i);
            Iterable arrayList2 = new ArrayList(i2);
            for (Object next : iterable) {
                if (hasKey(next)) {
                    arrayList.add(next);
                } else {
                    arrayList2.add(next);
                }
            }
            this.db.c();
            try {
                updateInTx(arrayList);
                insertInTx(arrayList2);
                this.db.g();
            } finally {
                this.db.b();
            }
        } else if (i2 > 0) {
            insertInTx((Iterable) iterable);
        } else if (i > 0) {
            updateInTx((Iterable) iterable);
        }
    }

    public void insertInTx(Iterable<T> iterable, boolean z) {
        executeInsertInTx(this.statements.c(), iterable, z);
    }

    public void insertOrReplaceInTx(Iterable<T> iterable) {
        insertOrReplaceInTx(iterable, isEntityUpdateable());
    }

    public void insertOrReplaceInTx(T... tArr) {
        insertOrReplaceInTx(Arrays.asList(tArr), isEntityUpdateable());
    }

    public void updateInsideSynchronized(T t, SQLiteStatement sQLiteStatement, boolean z) {
        bindValues(sQLiteStatement, (Object) t);
        int length = this.config.d.length + 1;
        Object key = getKey(t);
        if (key instanceof Long) {
            sQLiteStatement.bindLong(length, ((Long) key).longValue());
        } else if (key != null) {
            sQLiteStatement.bindString(length, key.toString());
        } else {
            throw new d("Cannot update entity without key - was it inserted before?");
        }
        sQLiteStatement.execute();
        attachEntity(key, t, z);
    }

    public void updateInTx(T... tArr) {
        updateInTx(Arrays.asList(tArr));
    }
}
